package com.liutaw.nanjingair.utils;

import android.content.Context;
import android.os.Build;
import android.os.Environment;

import java.io.File;

/**
 * Created by liutao on 16/3/16.
 */
public class FileUtils {
    public static final String DRAWABLE_PREFIX_DAY = "d";
    public static final String DRAWABLE_PREFIX_NIGHT = "n";

    public static File getExternalCacheDir(final Context context) {
        if (hasExternalCacheDir())
            return context.getExternalCacheDir();

        // Before Froyo we need to construct the external cache dir ourselves
        final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/";
        return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
    }

    public static boolean hasExternalCacheDir() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
    }


    public static int getResId(Context context, String resString) {
        return context.getResources().getIdentifier(FileUtils.DRAWABLE_PREFIX_DAY + resString, "drawable", context.getPackageName());
    }
}
